#ifndef SERVER_H
#define SERVER_H

#include <QList>
#include <QObject>
#include <QTcpSocket>
#include <QTcpServer>
#include <QJsonObject>
#include <QSqlDatabase>


class usernode
{
public:
    usernode()
    {

    }
    usernode(QTcpSocket *userfd, const QString &userid)
    {
        this->userfd = userfd;
        this->userid = userid;
    }
    usernode(QTcpSocket *userfd, const QString &userid, const QString &username):usernode(userfd, userid)
    {
        this->username = username;
    }
    QTcpSocket *userfd;
    QString userid;
    QString username;
};

class server : public QObject
{
    Q_OBJECT
public:
    explicit server(QObject *parent = nullptr);
    void handle_signin(QTcpSocket *fd, const QJsonObject &);
    void handle_signup(QTcpSocket *fd, const QJsonObject &);
    void handle_getfriendslist(QTcpSocket *fd);
    void handle_sendmessage(QTcpSocket *fd, const QJsonObject &);
    void handle_findpasswd(QTcpSocket *fd, const QJsonObject &);
    void handle_cancel_signin(QTcpSocket *fd);
    ~server();

private:
    QTcpServer *tcpserver;
    QSqlDatabase mysql;//数据库操作句柄
    QList<usernode> userlist;//在线用户链表


    void brodcastNewclient(QTcpSocket *);
private slots:
    void handleconnection();
    void handledisconnect();
    void handleread();
signals:

};

#endif // SERVER_H
